package com.haoxuer.discover.site.freemaker;

import com.haoxuer.discover.common.freemarker.ListDirective;
import com.haoxuer.discover.data.page.Filter;
import com.haoxuer.discover.data.page.Pageable;
import com.haoxuer.discover.site.data.entity.Link;
import com.haoxuer.discover.site.data.service.LinkService;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;

public class LinkDirective extends ListDirective<Link> {

  @Override
  public List<Link> list() {

    Integer size = getInt("size");
    Integer id = getInt("id");
    Pageable pagex = new Pageable();
    pagex.setPageSize(size);
    pagex.setPageNumber(1);
    pagex.getFilters().add(Filter.eq("linkType.id", id));
    return linkService.list(0, size, pagex.getFilters(), pagex.getOrders());
  }

  @Autowired
  LinkService linkService;
}